<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	protected function _initResourceLoader() {
		$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
				'namespace' => '',
				'basePath'  => APPLICATION_PATH
		));
        $resourceLoader->addResourceType('model', 'models/', 'M')
                       ->addResourceType('form' , 'forms/' , 'F');
	}

    public function _initModuleLoader() {
        $front = Zend_Controller_Front::getInstance();
        $front->registerPlugin(new Apps_Controller_Plugin_ModuleConfig());
    }

    protected function _initRoutes() {
    	$frontController = Zend_Controller_Front::getInstance();
    	$frontController->setControllerDirectory(APPLICATION_PATH . "/controllers");
    	$router = $frontController->getRouter();

    	//tour
    	$routeTourDetail = new Zend_Controller_Router_Route_Regex(
    	        'tour/detail/(\d+)-(.+)\.html',
    	        array(
    	                'controller' => 'tour',
    	                'action'     => 'detail'
    	        ),
    	        array(
    	                1 => 'id',
    	                2 => 'title'
    	        ),
    	        'tour/detail/%d-%s.html'
    	);
    	$router->addRoute('tour-detail', $routeTourDetail);

    	$routeTourCategory = new Zend_Controller_Router_Route_Regex(
    	        'tour/([0-9]*)/(\d+)-(.+)-(.+)\.html',
    	        array(
    	                'controller' => 'tour',
    	                'action'     => 'category',
    	                'page'       => 1
    	                ),
    	        array(
    	                1 => 'page',
    	                2 => 'id',
    	                3 => 'c',
    	                4 => 'title'
    	                ),
    	        'tour/%d/%d-%d-%s.html'
    	        );
    	$router->addRoute('tour-category', $routeTourCategory);

    	$routeTourStyle = new Zend_Controller_Router_Route_Regex(
    	        'tour/trip-in-style/([0-9]*)/(\d+)-(.+)-(.+)\.html',
    	        array(
    	                'controller' => 'tour',
    	                'action'     => 'trip-in-style',
    	                'page'       => 1
    	                ),
    	        array(
    	                1 => 'page',
    	                2 => 'id',
    	                3 => 'c',
    	                4 => 'title'
    	                ),
    	        'tour/trip-in-style/%d/%d-%d-%s.html'
    	        );
    	$router->addRoute('tour-trip-in-style', $routeTourStyle);

    	//cruise
    	$routeCruiseDetail = new Zend_Controller_Router_Route_Regex(
    	        '(.+)/(.+)-(\d+)\.html',
    	        array(
    	                'controller' => 'cruise',
    	                'action'     => 'detail'
    	        ),
    	        array(
    	                1 => 'category_title',
    	                2 => 'title',
    	                3 => 'id',
    	        ),
    	        '%s/%s-%d.html'
    	);
    	$router->addRoute('cruise-detail', $routeCruiseDetail);

    	$routeCruiseCategory = new Zend_Controller_Router_Route_Regex(
    	        'cruise/([0-9]*)/(\d+)-(.+)-(.+)\.html',
    	        array(
    	                'controller' => 'cruise',
    	                'action'     => 'category',
    	                'page'       > 1
    	                ),
    	        array(
    	                1 => 'page',
    	                2 => 'id',
    	                3 => 'c',
    	                4 => 'title'
    	                ),
    	        'cruise/%d/%d-%d-%s.html'
    	        );
    	$router->addRoute('cruise-category', $routeCruiseCategory);

    	//destination
    	$routeDestination = new Zend_Controller_Router_Route_Regex(
    	        'destination/(\d+)/(.+)\.html',
    	        array(
    	                'controller' => 'destination',
    	                'action'     => 'index'
    	                ),
    	        array(
    	                1 => 'c',
    	                3 => 'name'
    	                ),
    	        'destination/%d/%s.html'
    	        );
    	$router->addRoute('destination', $routeDestination);

    	//hotel
    	$routeHotelRegion = new Zend_Controller_Router_Route_Regex(
    	        'hotel/(\d+)/(.+)\.html',
    	        array(
    	                'controller' => 'hotel',
    	                'action'     => 'region'
    	                ),
    	        array(
    	                1 => 'id',
    	                3 => 'name'
    	                ),
    	        'hotel/%d/%s.html'
    	        );
    	$router->addRoute('hotel-region', $routeHotelRegion);

    	$routeHotelDetail = new Zend_Controller_Router_Route_Regex(
    	        'hotel/detail/(\d+)-(.+)\.html',
    	        array(
    	                'controller' => 'hotel',
    	                'action'     => 'detail'
    	        ),
    	        array(
    	                1 => 'id',
    	                2 => 'title'
    	        ),
    	        'hotel/detail/%d-%s.html'
    	);
    	$router->addRoute('hotel-detail', $routeHotelDetail);

    	//promotion
    	$routePromotionType = new Zend_Controller_Router_Route_Regex(
    	        'promotion/(\d+)/([0-9]*)/(.+)\.html',
    	        array(
    	                'controller' => 'promotion',
    	                'action'     => 'type',
    	                'page'       => 1
    	        ),
    	        array(
    	                1 => 'type',
    	                2 => 'page',
    	                3 => 'title',
    	        ),
    	        'promotion/%d/%d/%s.html'
    	);
    	$router->addRoute('promotion', $routePromotionType);

    	//event
    	$routeEventDetail = new Zend_Controller_Router_Route_Regex(
    	        'event/detail/(\d+)-(.+)\.html',
    	        array(
    	                'controller' => 'event',
    	                'action'     => 'detail'
    	        ),
    	        array(
    	                1 => 'id',
    	                2 => 'title'
    	        ),
    	        'event/detail/%d-%s.html'
    	);
    	$router->addRoute('event-detail', $routeEventDetail);

    	//article
    	$routeArticleDetail = new Zend_Controller_Router_Route_Regex(
    	        'article/detail/(\d+)-(\d+)-(.+)\.html',
    	        array(
    	                'controller' => 'article',
    	                'action'     => 'detail'
    	        ),
    	        array(
    	                1 => 't',
    	                2 => 'id',
    	                3 => 'title'
    	        ),
    	        'article/detail/%d-%d-%s.html'
    	);
    	$router->addRoute('article-detail', $routeArticleDetail);
    	//mice
    	$routeMiceDetail = new Zend_Controller_Router_Route_Regex(
    	        'mice/detail/(\d+)-(\d+)-(.+)\.html',
    	        array(
    	                'controller' => 'mice',
    	                'action'     => 'detail'
    	        ),
    	        array(
    	                1 => 't',
    	                2 => 'id',
    	                3 => 'title'
    	        ),
    	        'mice/detail/%d-%d-%s.html'
    	);
    	$router->addRoute('mice-detail', $routeMiceDetail);

    	//country article
    	$routeCountryArticleDetail = new Zend_Controller_Router_Route_Regex(
    	        'destination/detail/(\d+)-(\d+)-(.+)\.html',
    	        array(
    	                'controller' => 'destination',
    	                'action'     => 'detail-country'
    	        ),
    	        array(
    	                1 => 't',
    	                2 => 'id',
    	                3 => 'title'
    	        ),
    	        'destination/detail/%d-%d-%s.html'
    	);
    	$router->addRoute('destination-detail', $routeCountryArticleDetail);

    	//Region article
    	$routeRegionArticleDetail = new Zend_Controller_Router_Route_Regex(
    	        'travel-destination/detail/(\d+)-(\d+)-(.+)\.html',
    	        array(
    	                'controller' => 'destination',
    	                'action'     => 'detail-region'
    	        ),
    	        array(
    	                1 => 't',
    	                2 => 'id',
    	                3 => 'title'
    	        ),
    	        '/travel-destination/detail/%d-%d-%s.html'
    	);
    	$router->addRoute('article-detail-region', $routeRegionArticleDetail);

    	$routeCountryArticleTravelTips = new Zend_Controller_Router_Route_Regex(
    			'travel-tips/(.+)(\d+)\.html',
    			array(
    					'controller' => 'destination',
    					'action'     => 'travel-tips'
    			),
    			array(
    					1 => 'name',
    					2 => 'id'
    			),
    			'travel-tips/%s-%d.html'
    	);
    	$router->addRoute('routeCountryArticle', $routeCountryArticleTravelTips);
    	$routeCountryArticleGI = new Zend_Controller_Router_Route_Regex(
    			'general-information/(.+)(\d+)\.html',
    			array(
    					'controller' => 'destination',
    					'action'     => 'general-information'
    			),
    			array(
    					1 => 'name',
    					2 => 'id'
    			),
    			'general-information/%s-%d.html'
    	);
    	$router->addRoute('routeCountryArticleGI', $routeCountryArticleGI);
    	$routeCountryArticleTD = new Zend_Controller_Router_Route_Regex(
    			'travel-destination/(.+)(\d+)\.html',
    			array(
    					'controller' => 'destination',
    					'action'     => 'travel-destination'
    			),
    			array(
    					1 => 'name',
    					2 => 'id'
    			),
    			'travel-destination/%s-%d.html'
    	);
    	$router->addRoute('routeCountryArticleTD', $routeCountryArticleTD);
    	$routeCountryArticleTN = new Zend_Controller_Router_Route_Regex(
    			'travel-news/(.+)(\d+)\.html',
    			array(
    					'controller' => 'destination',
    					'action'     => 'travel-news'
    			),
    			array(
    					1 => 'name',
    					2 => 'id'
    			),
    			'travel-news/%s-%d.html'
    	);
    	$router->addRoute('routeCountryArticleTN', $routeCountryArticleTN);

    }

    public function _initAcl() {
    	$this->bootstrap('db');

    	$frontController = Zend_Controller_Front::getInstance();
    	$frontController->registerPlugin(new Apps_Controller_Plugin_Acl());
    }
}